package com.itshidu.jiaowu.controller;


import com.itshidu.jiaowu.service.ClassesService;
import com.itshidu.jiaowu.service.StudentClassesService;
import com.itshidu.jiaowu.util.CookieUtils;
import com.itshidu.jiaowu.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XiaZengming123
 * @since 2019-07-08
 */
@Controller
public class StudentClassesAction {

    @Autowired ClassesService classesservice;
    @Autowired StudentClassesService studentClassesService;

    //管理学生
    @ResponseBody
    @RequestMapping("/admin/classTimesId")
    public Result selectstudents(Long id, HttpServletResponse response){
        CookieUtils.writeCookie(response,"classInfo",id.toString());
        return Result.of().put("code",200);
    }
    //
    @ResponseBody
    @RequestMapping("/admin/classInfo/select")
    public Result selectstudents(Integer page,Integer limit,HttpServletRequest request){
        String idd=CookieUtils.getCookie(request,"classInfo");
        Long id=Long.valueOf(idd);
        Result r=studentClassesService.selectS(page,limit,id);
        return r;
    }


    //删除班级内的学生
    @ResponseBody
    @RequestMapping("/admin/teacherInfo/del")
    public void deleteStudent(Long id){
        studentClassesService.removeById(id);
    }

    //给某个班级添加学生
    @ResponseBody
    @RequestMapping("admin/class/student_add")
    public Result ClassStudentAdd(String name,String dateTime, HttpServletRequest request) {

        return studentClassesService.ClassStudentAdd(name,dateTime,request);
    }

}

